<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
  </head>
  <body>
    <div id="app">
      <input
        type="text"
        name=""
        id=""
        placeholder="请输入用户名"
        v-model.lazy="name"
      /><span>{{info}}</span>
    </div>
    <script src="./vue.js"></script>
    <script>
      const vm = new Vue({
        el: "#app",
        data: { info: "", name: "", arr: ["admin", "little", "cici", "lucy"] },
        methods: {
          check() {
            setTimeout(()=>{
              console.log(this.name);
              let i = this.arr.find(item => item==this.name);
              console.log(i);
              if (i) {
              this.info = "用户名已存在";
            } else {
              this.info = "用户名可用";
              
            }
            },500)
          },
        },
        watch: {
          name(){
            this.info="正在验证.."
            this.check()
          }
        },
      });
    </script>
  </body>
</html>
